package com.developer.platform.domain.security;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.Method;
import com.developer.platform.infrastructure.enums.MenuEnum;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

/**
 * 身份认证实体
 *
 * @author ：qiaoliang
 * @date ：2020-11-04
 */
public class AuthorizationInfo {
    /**父级ID**/
    private long id;
    /**父级ID**/
    private long parentId;
    /** url **/
    private String url;
    /** 菜单类型 **/
    private MenuEnum type;
    /** 接口类型 **/
    private Method method;
    /** 访问接口所需标识 **/
    private String mark;
    /** 路由地址 **/
    private String path;
    /** 路由路径 **/
    private String component;
    /** 路由名称 **/
    private String name;
    /** 路由标题 **/
    private String title;
    /** 路由图标 **/
    private String icon;
    /** 重定向地址 **/
    private String redirect;

    /**
     * 获取当前访问地址所需权限
     *
     * @author ：qiaoliang
     * @param request : 当前请求
     * @return boolean
     * @date 2020-11-04 08:39
     */
    public boolean matches(HttpServletRequest request){
        if(StrUtil.isNotBlank(this.getUrl()) && Objects.nonNull(this.getMethod())){
            return new AntPathRequestMatcher(this.getUrl(), this.getMethod().name()).matches(request);
        }
        return false;
    }

    public AuthorizationInfo() {
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getParentId() {
        return parentId;
    }

    public void setParentId(long parentId) {
        this.parentId = parentId;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public MenuEnum getType() {
        return type;
    }

    public void setType(MenuEnum type) {
        this.type = type;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public String getMark() {
        return mark;
    }

    public void setMark(String mark) {
        this.mark = mark;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getRedirect() {
        return redirect;
    }

    public void setRedirect(String redirect) {
        this.redirect = redirect;
    }
}
